package com.hdax.dm.mapstructs;

import com.hdax.dm.dto.OrderDto;
import com.hdax.dm.order.DmOrder;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Mapper(componentModel = "spring")
public abstract class OrderDtoMapper {
    protected String calcTime(LocalDateTime createdTime){
        LocalDateTime endTime = createdTime.plusMinutes(15L);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return dateTimeFormatter.format(endTime);
    }

    @Mappings({
            @Mapping(target = "num" ,source = "totalCount"),
            @Mapping(target = "sellTime",source = "createdTime"),
            @Mapping(target = "endTime" ,expression = "java(calcTime(order.getCreatedTime()))")
    })
    public abstract OrderDto orderDto(DmOrder order);


    public abstract List<OrderDto> orderDto(List<DmOrder> order);


}
